<template>
  <el-dialog
      v-model="toolLedgerEditWinDialog"
      title="编辑工装夹具清单"
      width="50%">
    <template #default>
      <el-form :model="editToolLedger" label-width="auto">
      <el-form-item label="工装夹具名称">
        <el-input v-model="editToolLedger.toolLedgerName"/>
      </el-form-item>
      <el-form-item label="品牌">
        <el-input v-model="editToolLedger.toolLedgerBrand"/>
      </el-form-item>
      <el-form-item label="型号">
        <el-input v-model="editToolLedger.toolLedgerSpec"/>
      </el-form-item>
      <el-form-item label="工装夹具类型">
        <el-select v-model="editToolLedger.toolLedgerType"/>
          <el-option
            v-for="t in types"
            :key="t.toolTypeId"
            :label="t.toolTypeName"
            :value="t.toolTypeId">
          </el-option>
<!--        <el-input v-model="editToolLedger.toolLedgerType"/>-->
      </el-form-item>
      <el-form-item label="数量">
        <el-input v-model="editToolLedger.toolInventoryNum"/>
      </el-form-item>
      <el-form-item label="可用数量">
        <el-input v-model="editToolLedger.toolAvailableNum"/>
      </el-form-item>
        <el-form-item label="下次保养周期">
          <el-input v-model="editToolLedger.serviceInterval"/>
        </el-form-item>
      <el-row>
<!--        <el-col :span="12">-->
<!--          <el-form-item label="下一次保养日期">-->
<!--            <el-date-picker-->
<!--                v-model="editToolLedger.maintainDate"-->
<!--                type="date"-->
<!--                value-format="YYYY-MM-DD"-->
<!--            />-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--      </el-row>-->
          <el-col :span="12">
            <el-form-item label="下一次保养日期">
              <el-date-picker
                  v-model="editToolLedger.maintainDate"
                  type="date"
                  value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
        </el-row>
      <el-form-item label="状态">
        <el-select v-model="editToolLedger.toolLedgerStatus">
          <el-option value="1" label="在库"/>
          <el-option value="2" label="被领用"/>
          <el-option value="3" label="报废"/>
          <el-option value="4" label="维修中"/>
        </el-select>
      </el-form-item>
      <el-form-item label="保养维护类型">
        <el-radio-group v-model="editToolLedger.maintainType">
          <el-radio value="定期维护" size="large">定期维护</el-radio>
          <el-radio value="按使用次数维护" size="large">按使用次数维护</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="editToolLedger.toolTypeNotes"/>
      </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="editToolTypeSubmit">
          提交
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>

import {onMounted, ref, watch} from "vue";
import ledgerRequest from "@/api/ledger.js";
import {ElMessage} from "element-plus";
import maintainPlanRequest from "@/api/maintainPlan.js";
import toolsTypeRequest from "@/api/toolsType.js";
import toolsLedgerRequest from "@/api/toolsLedger.js";
const props = defineProps(['toolLedgerId']);
const emits = defineEmits(['editComplate']);
let toolLedgerEditWinDialog = ref(false);
let editToolLedger = ref({});
let types = ref({});
function loadType(){
  toolsLedgerRequest.selectByType(res=>{
    types.value=res.data;
  })
}
function cancel(){
  editToolLedger = ref({});
  toolLedgerEditWinDialog.value =false;
}
function editToolTypeSubmit(){
  toolsLedgerRequest.updateToolLedger(editToolLedger.value,res=>{
    if (res.code == 200){
      ElMessage({
        type:"success",
        message:"修改成功"
      });
      cancel()
      emits('editComplate');
    }else {
      ElMessage({
        type:"warning",
        message:"修改失败"
      })
    }
  })
}

function loadToolLedgerById(){
  toolsLedgerRequest.selectById(props.toolLedgerId,res=>{
    if (res.data){
      editToolLedger.value =res.data;
      toolLedgerEditWinDialog.value = true;
    }
  })
}

watch(()=>props.toolLedgerId,()=>{
  if(props.toolLedgerId){
    loadToolLedgerById();
  }
});

</script>

<style scoped>

</style>